package com.maple.admin.controller;

import com.maple.admin.common.util.AjaxJson;
import com.maple.admin.domain.entity.Fruit;
import com.maple.admin.domain.entity.Order;
import com.maple.admin.service.FruitService;
import com.maple.admin.service.LikeService;
import com.maple.admin.service.ProductTwoService;
import io.swagger.annotations.Api;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/fruit")
@Api(value = "fruit", tags = "水果百科模块")
public class FruitController {

    @Resource
    private FruitService fruitService;

    @Resource
    private LikeService likeService;

    @Resource
    private ProductTwoService productTwoService;

    @GetMapping("/list")
    public AjaxJson selectAll(){

        return  AjaxJson.getSuccessData(fruitService.list());
    }
    @GetMapping("/detail/{cid}")
    public AjaxJson getOrderDetail(@PathVariable Integer cid){

        return  AjaxJson.getSuccessData(likeService.getListByCid(cid));
    }

    @PostMapping("/save")
    public AjaxJson saveFruit(@RequestBody Fruit fruit){

        return  AjaxJson.getSuccessData(fruitService.saveOrUpdate(fruit));
    }

    @GetMapping("/getFruitDict")
    public AjaxJson getFruitDict(){


        return AjaxJson.getSuccessData(productTwoService.list());
    }

    @GetMapping("/delete/{cid}")
    @Transactional
    public AjaxJson delete(@PathVariable Integer cid){

       /* QueryWrapper wrapper  = new QueryWrapper<>();
        wrapper.eq("sid",sid);
        applyService.remove(wrapper);
        detailService.remove(wrapper);*/

        return AjaxJson.getSuccessData(fruitService.removeById(cid));
    }
}
